<template>
	<view class="page">
		<view class="head">
			<view class="job-form-notice">
				<view class="job-form-notice-title"><u-tag text="公告" type="warning"></u-tag></view>
				<view class="job-form-notice-content"><u-parse :content="positionNoticeContent" :selectable="true"></u-parse></view>
			</view>
			<view class="job-form-set-menu">
				<view class="job-form-set-menu-tips">您还可以免费发布<text>{{ positionReleasesNumber }}</text>条招聘</view>
				<view class="job-form-set-menu-buy" @click="goToBuyVip()">购买套餐></view>
			</view>
		</view>
		<u-gap height="10" bgColor="#f9f9f9"></u-gap>
		<view class="body">
			<view class="job-form-list">
				<view class="job-form-item">
					<view class="job-form-item-title">
						求职类型
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<u-radio-group v-model="jobType" placement="row" @change="jobTyypeChange">
							<view class="job-from-item-content-radio"><u-radio activeColor="#c8000a" label="全职" name="1"></u-radio></view>
							<view class="job-from-item-content-radio"><u-radio activeColor="#c8000a" label="兼职" name="2"></u-radio></view>
						</u-radio-group>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item">
					<view class="job-form-item-title">
						职位名称
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<u--input
							placeholder="请输入职位名称"
							placeholderStyle="font-size: 28rpx;color: #808080;"
							style="margin-left: 10rpx;"
							v-model="jobTitle"
							border="none"
							@blur="checkTextContent"
						></u--input>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item">
					<view class="job-form-item-title">
						职位类别
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<uni-data-picker
							placeholder="请选择职位类别"
							popup-title="请选择职位类别"
							:clearIcon="false"
							split="->"
							:localdata="positionClassDataTree"
							@change="positionOnchange"
							class="job-ld-select"
							ref="positionSelect"
						></uni-data-picker>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>


				<view class="job-form-item" :style="jobType == 1 ? '' : 'display:none;'">
						<view class="job-form-item-title">
							薪资待遇
							<text>*</text>
						</view>
						<view class="job-from-item-content">
							<uni-data-picker
								placeholder="请选薪资待遇"
								popup-title="请选薪资待遇"
								:clearIcon="false"
								:localdata="FullTimeSalaryClassDataTree"
								v-model="fullTimeSalary"
								@change="fullTimeSalaryOnchange"
								class="job-ld-select"
							></uni-data-picker>
						</view>
					</view>

				<u-gap :height="jobType == 1 ? '2' : '0'" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item" :style="fullTimeSalary == '0' ? '' : 'display:none;'">
						<view class="job-form-item-title">
							输入待遇
							<text>*</text>
						</view>
						<view class="job-from-item-content">
							<u--input
								placeholder="最低工资"
								placeholderStyle="font-size: 28rpx;color: #808080;"
								style="margin-left: 10rpx;"
								v-model="fullTimeMinimumWage"
								border="none"
								type="number"
							></u--input>
							<text>至</text>
							<u--input
								placeholder="最高工资"
								placeholderStyle="font-size: 28rpx;color: #808080;"
								style="margin-left: 10rpx;"
								v-model="fullTimeMaximumWage"
								border="none"
								type="number"
							></u--input>
							<text>元/月</text>
						</view>
					</view>
					
				<u-gap :height="fullTimeSalary == '0' ? '2' : '0'" bgColor="#f9f9f9"></u-gap>
				
				<view class="job-form-item"  :style="jobType == 2 ? '' : 'display:none;'">
						<view class="job-form-item-title">
							薪资待遇
							<text>*</text>
						</view>
						<view class="job-from-item-three-content">
							<u--input
								placeholder="请输入薪资待遇"
								placeholderStyle="font-size: 28rpx;color: #808080;"
								style="margin-left: 10rpx;"
								v-model="partTimeSalary"
								border="none"
								type="number"
							></u--input>
						</view>
						<u-line direction="col" length="40%" color="#999999" :hairline="false"></u-line>
						<view class="job-from-item-three-unit">
							<ld-select
								:list="salaryUnitClassDataTree"
								labelKey="label"
								valueKey="value"
								placeholder="请选择薪资结算"
								v-model="salaryUnit"
								:clearable="false"
								:inputStyle="{ color: '#3173bd' }"
								bgColor="#ffffff"
								selectColor="#c70000"
								@change="salaryUnitChange"
								class="job-ld-select"
							></ld-select>
						</view>
					</view>

				<u-gap :height="jobType == 2 ? '2' : '0'" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item"  :style="jobType == 2 ? '' : 'display:none;'">
						<view class="job-form-item-title">
							结算方式
							<text>*</text>
						</view>
						<view class="job-from-item-content">
							<ld-select
								:list="settlementMethodClassDataTree"
								labelKey="text"
								valueKey="value"
								placeholder="请选结算方式"
								v-model="settlementMethod"
								:clearable="false"
								:inputStyle="{ color: '#3173bd' }"
								bgColor="#ffffff"
								selectColor="#c70000"
								@change="settlementMethodchange"
								class="job-ld-select"
							></ld-select>
						</view>
					</view>

				<u-gap :height="jobType == 2 ? '2' : '0'" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item">
					<view class="job-form-item-title">招聘人数</view>
					<view class="job-from-item-content">
						<u--input
							placeholder="请填写人数，留空默认'若干'"
							placeholderStyle="font-size: 28rpx;color: #808080;"
							style="margin-left: 10rpx;"
							v-model="jobRecruitNumber"
							border="none"
							type="number"
						></u--input>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item-single-line">
					<view class="job-form-item-single-line-title">
						职位福利
						<text>（至多6个，没有可不选）</text>
					</view>
				</view>

				<view class="job-form-item-single-line">
					<view class="job-form-item-position-tabs">
						<view
							class="job-form-item-position-tabs-item"
							:class="positionItem.checked ? 'job-form-item-position-tabs-item-select' : ''"
							v-for="(positionItem, index) in jobPositionWelfareTabs"
							:key="index"
							@click="positionWelfareTabsSelect(index, positionItem.name)"
						>
							{{ positionItem.name }}
						</view>
					</view>
				</view>

				<view class="groupTitle">公司信息</view>
				<view class="job-form-item">
					<view class="job-form-item-title">
						公司名称
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<u--input
							placeholder="请输入公司名称"
							placeholderStyle="font-size: 28rpx;color: #808080;"
							style="margin-left: 10rpx;"
							v-model="companyName"
							border="none"
						></u--input>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item">
					<view class="job-form-item-title">
						工作区域
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<uni-data-picker
							placeholder="请选工作区域"
							popup-title="请选工作区域"
							:clearIcon="false"
							:localdata="jobAreaClassDataTree"
							v-model="jobArea"
							split="->"
							@change="jobAreaOnchange"
							class="job-ld-select"
						></uni-data-picker>
					</view>
				</view>
				<u-gap height="2" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item">
					<view class="job-form-item-title">
						工作地址
						<text>*</text>
					</view>
					<view class="job-from-item-four-content">
						<u--input
							placeholderStyle="font-size: 28rpx;color: #808080;"
							style="margin-left: 10rpx;"
							v-model="JobAddress"
							border="none"
						></u--input>
					</view>
					<u-line direction="col" length="40%" margin="10rpx" color="#999999" :hairline="false"></u-line>
					<view class="job-from-item-four-text">
						<text @click="isShowAddressPopup = !isShowAddressPopup">定位</text>
						<u-popup :show="isShowAddressPopup" :borderRadius="10" :round="true"  :closeOnClickOverlay="true" mode="bottom" @close="closeAddressPopup()">
								<view class="job-fromm-item-popup">
						            <view class="job-fromm-item-popup-title">
						            	<view class="job-from-item-popup-title-left">

						            	</view>
										<view class="job-from-item-popup-title-center">
											选择位置
										</view>
										<view class="job-from-item-popup-title-right" @click="closeAddressPopup()">
											取消
										</view>
						            </view>									
									<view class="job-from-item-popup-content">
										<view class="job-from-item-popup-content-list">
											<view class="job-from-item-popup-content-item" @click="getLocation()">
												我当前位置
											</view>
											<view class="job-from-item-popup-content-item" @click="selectLocationAddress()">
												地图上选点
											</view>
										</view>
									</view>
								</view>
							</u-popup>
						
					</view>
					
				</view>
				
				<u-gap height="2" bgColor="#f9f9f9"></u-gap>
				
				<view class="job-form-item">
					<view class="job-form-item-title">
						联系人
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<u--input
							placeholder="请输入联系人"
							placeholderStyle="font-size: 28rpx;color: #808080;"
							style="margin-left: 10rpx;"
							v-model="contacts"
							border="none"
							@blur="checkTextContent"
						></u--input>
					</view>
				</view>
				
				<u-gap height="2" bgColor="#f9f9f9"></u-gap>

				<view class="job-form-item">
					<view class="job-form-item-title">
						联系电话
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<u--input
							placeholder="请输入联系电话"
							placeholderStyle="font-size: 28rpx;color: #808080;"
							style="margin-left: 10rpx;"
							v-model="contactsNumber"
							border="none"
						></u--input>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>
				
				<view class="job-form-item">
					<view class="job-form-item-title" style="color:#c8000a;">
						招聘置顶
						<text>*</text>
					</view>
					<view class="job-from-item-content">
						<uni-data-picker
							placeholder="请选置顶"
							popup-title="请选置顶"
							:clearIcon="false"
							:localdata="toppingClassDataTree"
							v-model="topping"
							@change="toppingSelectChange"
							class="job-ld-select"
						></uni-data-picker>
					</view>
				</view>

				<view class="groupTitle">岗位需求</view>

				<view class="job-form-item">
					<view class="job-form-item-title">性别要求</view>
					<view class="job-from-item-content">
						<ld-select
							:list="genderClassDataTree"
							labelKey="label"
							valueKey="value"
							placeholder="请选性别要求"
							v-model="gender"
							:clearable="false"
							bgColor="#ffffff"
							selectColor="#c70000"
							@change="genderSelectChange"
							class="job-ld-select"
						></ld-select>
					</view>
				</view>

				<u-gap height="2" bgColor="#f9f9f9"></u-gap>
				
				<view class="job-form-item">
					<view class="job-form-item-title">年龄要求</view>
					<view class="job-from-item-content">
						<ld-select
							:list="ageClassDataTree"
							labelKey="label"
							valueKey="value"
							placeholder="请选年龄要求"
							v-model="age"
							:clearable="false"
							bgColor="#ffffff"
							selectColor="#c70000"
							@change="ageSelectChange"
							class="job-ld-select"
						></ld-select>
					</view>
				</view>
				
				<u-gap height="2" bgColor="#f9f9f9"></u-gap>
				
				<view class="job-form-item">
					<view class="job-form-item-title">学历要求</view>
					<view class="job-from-item-content">
						<ld-select
							:list="educationClassDataTree"
							labelKey="label"
							valueKey="value"
							placeholder="请选学历要求"
							v-model="education"
							:clearable="false"
							bgColor="#ffffff"
							selectColor="#c70000"
							@change="educationSelectChange"
							class="job-ld-select"
						></ld-select>
					</view>
				</view>
				
				<u-gap height="2" bgColor="#f9f9f9"></u-gap>
				
				<view class="job-form-item">
					<view class="job-form-item-title">工作经验</view>
					<view class="job-from-item-content">
						<ld-select
							:list="workExperienceClassDataTree"
							labelKey="label"
							valueKey="value"
							placeholder="请选工作经验"
							v-model="workExperience"
							:clearable="false"
							bgColor="#ffffff"
							selectColor="#c70000"
							@change="workExperienceSelectChange"
							class="job-ld-select"
						></ld-select>
					</view>
				</view>
				<view class="groupTitle">职位描述<text>*</text></view>
				<view class="groupContent">
					<u--textarea v-model="jobDescription" placeholder="请输入职位描述，让求职者快速了解职位" placeholderStyle="font-size: 28rpx;color: #808080;" @blur="checkTextContent"></u--textarea>
				</view>
				<view class="groupTitle">职位介绍图片</view>
				<view class="groupContent">
					<view class="jobDescriptionImagesGroup">
						<!-- <u-upload
							:fileList="jobDescriptionImages"
							name="3"
							multiple
							:maxCount="10"
							:previewFullImage="true"
							:sizeType="['compressed']"
							@afterRead="afterRead"
							@delete="deletePic"
							 width="150rpx"
							 height="150rpx"
						>
						<image src="/static/job/pic.png" mode="widthFix" style="width: 150rpx;height: 150rpx;"></image>
						</u-upload> -->
						<uni-file-picker
							limit="9"
							v-model="jobDescriptionImages"
							fileMediatype="image"
							mode="grid"
							:imageStyles="imageStyles"
							ref="jobDescriptionImageList"
							@select="jobDescriptionImageListSelect"
							@delete="jobDescriptionImageListDelete"
						></uni-file-picker>
					</view>
				</view>
				<template v-if="!isIosPhone && positionReleasesNumber == 0 && jobID ==''">
					<view class="groupTitle readText text28rpx">发布天数*</view>
					<view class="groupContent">
						<view class="jobReleaseDaysGroup">
							
							<view class="jobReleaseDaysItem"
								v-for="(releaseDaysItem, index) in releaseDaysDataTree"
								:key="index"
								@click="jobReleaseDaysSelect(releaseDaysItem.ID)"
								:class="releaseDays == releaseDaysItem.ID ? 'select' : ''">
								<view class="jobReleaseDaysTitle">
									<image src="../../static/job/yes1.png" class="jobReleaseDaysSelectImage"></image>
								</view>
								<view class="jobReleaseDaysContent">
									<view class="jobReleaseDay">
										发布{{ releaseDaysItem.Day }}天
									</view>
									<view class="jobReleasePrice">
										<text>￥</text>{{ releaseDaysItem.Price }}
									</view>
									<view class="jobReleaseTips">
										暂时不支持非会员发布
									</view>
								</view>
							</view>
						</view>
					</view>
				</template>
				<view class="job-post-subimt" @click="$u.throttle(infoSubmit, 2000)">
					<u-button type="primary" text="发布"></u-button>
				</view>
				
			</view>
		</view>
		<view class="bottom u-safe-bottom u-safe-area-inset-bottom"></view>
		<QuickMessage ref="message"></QuickMessage>
	</view>
</template>

<script>
import QuickMessage from '@/components/quick-message/quick-message.vue';
export default {
	data() {
		return {
			imageStyles: {
				width: '33%',
				height: '200rpx',
				border: {
					color: '#d9d9d9',
					width: '2rpx',
					style: 'dashed',
					radius: '5%'
				}
			},//  上传图片样式
			positionNoticeContent: '', // 职位发布公告
			positionReleasesNumber: '', // 发布条数
			jobID: '',  // 职位ID
			jobTitle: '', //职位名称
			jobType: '1', // 职位类型
			positionClass: '', // 职位类别值
			positionClassChildren: '', // 职位类别子类值
			positionClassDataTree: [], //职位类别选项
			fullTimePositionClassDataTree: [],	// 全职职位列表
			partTimePositionClassDataTree:[],	// 兼职职位列表
			fullTimeSalary: '', // 全职薪资待遇
			fullTimeMinimumWage: '', // 全职自定义薪资最低工资
			fullTimeMaximumWage: '', //全职自定义薪资最高工资
			FullTimeSalaryClassDataTree: [
				// 薪资待遇选项
				{
					text: '自定义待遇',
					value: 0
				},
			], 	// 薪资待遇选项
			partTimeSalary: '', // 兼职薪资待遇值
			salaryUnit: 0, // 兼职薪资结算周期
			salaryUnitClassDataTree: [
				//兼职薪资结算周期选项
				{
					value: 0,
					label: '元/小时'
				},
				{
					value: 1,
					label: '元/天'
				}
			],
			settlementMethod: 0, //兼职薪资结算方式
			settlementMethodClassDataTree: [
				//兼职薪资结算方式
				{
					value: 0,
					text: '不限'
				},
				{
					value: 1,
					text: '日结'
				},
				{
					value: 2,
					text: '周结'
				},
				{
					value: 3,
					text: '月结'
				},
				{
					value: 4,
					text: '完工结算'
				}
			],
			jobRecruitNumber: '', // 招聘人数
			jobPositionWelfareSelectTabs: [], // 职位福利值
			jobPositionWelfareTabs: [], // 职位福利选项
			companyName: '', //公司名称
			jobCity: '',		// 工作区域选择市的值ID
			jobArea: '',	// 工作区域选择区的值ID
			jobAreaClassDataTree: [], //工作区域选项
			JobAddress: '', // 获取当前位置物理地址
			longitude: null, // 获取经度
			latitude: null, //  获取维度
			isShowAddressPopup: false, //是否显示定位选择框
			contacts: '', //联系人
			contactsNumber: '', // 联系电话
			topping:'',// 置顶选择值
			toppingClassDataTree:[
				// 置顶选择项
				{
					text: '不置顶',
					value: 0
				}
			], //置顶选项
			gender: 0, // 性别值
			genderClassDataTree: [
				//性别选项
				{
					value: 0,
					label: '不限性别'
				},
				{
					value: 1,
					label: '男'
				},
				{
					value: 2,
					label: '女'
				}
			],
			age: 0, // 年龄要求值
			ageClassDataTree:[
				// 年龄要求选项
				{
					value: 0,
					label: '不限年龄'
				},
			],
			education: 0, //学历要求值
			educationClassDataTree:[
				// 学历要求选项
				{
					value: 0,
					label: '不限学历'
				}
			],
			workExperience: 0, //工作经验要求值
			workExperienceClassDataTree:[
				// 工作经验选项
				{
					value: 0,
					label: '不限经验'
				}
			],
			jobDescription: '', // 职位描述
			jobDescriptionImages: [],// 职位介绍图片
			releaseDays: 0, // 发布天数ID
			releaseDaysDataTree:[], // 发布天数列表
			infoParams: { openid: getApp().globalData.openid, cid: getApp().globalData.cityId }, // 传递参数组合对象
			isSubmit: true,	// 是否可以提交
		};
	},
	async onLoad(res) {
		await this.$onLaunched;
		this.getJobIsCompanyAuthentication()
		this.getLocation();
	},
	methods: {
		//判断是否进行企业认证
		getJobIsCompanyAuthentication() {
			this.$api.getJobIsCompanyAuthentication({openid: getApp().globalData.openid,}).then(res => {
				if(res.status == 1) {
					this.getJobPostPosition()
				} else {
					this.goToEnterPriseAuth()
				}
				
			})
		},
		getJobPostPosition() {
			this.$api.getJobPostPosition({openid: getApp().globalData.openid,}).then(res => {
				// 组合公告
				this.positionNoticeContent = res.data.GongGao
				// 组合发布条数
				this.positionReleasesNumber = res.data.ZPNum
				// 把全职时参数列表复制到临时变量中
				this.fullTimePositionClassDataTree = res.data.QZhiWeiList
				this.fullTimePositionData()
				// 把兼职时参数列表复制到临时变量中
				this.partTimePositionClassDataTree = res.data.JZZWClass

				// 组合全职薪资待遇列表
				for(let fullTimSalaryItem of res.data.XZList) {
					this.FullTimeSalaryClassDataTree.push({
						text: fullTimSalaryItem.XZName,
						value: fullTimSalaryItem.ID,
					})
				}
				
				// 组合职位福利
				for(let welfareItem of res.data.FLList) {
					this.jobPositionWelfareTabs.push({
						name: welfareItem.FLName,
						checked: false,
						value: welfareItem.ID
					})
				}
				// 公司信息组合
				// 组合公司名称
				this.companyName = res.data.QYName
				// 组合联系人
				this.contacts = res.data.LXPerson
				// 组合联系电话
				this.contactsNumber = res.data.LXPhone
				
				
				// 组合工作区域
				for(let cityItem of res.data.DiYuList) {
					let itemCity={
						text: cityItem.Name,
						value: cityItem.ID,
						children: []
					}
					let itemArea= []
					for(let areaItem of cityItem.ddtype_lst) {
						itemArea.push({
							text: areaItem.dd_name,
							value: areaItem.dd_id
						})
					}
					itemCity.children = itemArea
					this.jobAreaClassDataTree.push(itemCity)
				}
				
				// 组合招聘置顶列表
				for(let toppingItem of res.data.ZDList) {
					this.toppingClassDataTree.push({
						text: toppingItem.Title + '（' + toppingItem.Price + '元）',
						value: toppingItem.ID
					})
				}
				
				// 组合年龄要求列表
				for(let ageItem of res.data.AgeList) {
					this.ageClassDataTree.push(
						{
							value: ageItem.ID,
							label: ageItem.AgeName
						}
					)
				}
				
				// 组合学历要求列表
				for(let educationItem of res.data.XLList) {
					this.educationClassDataTree.push(
					{
						value: educationItem.ID,
						label: educationItem.XLName
					})
				}
				
				// 组合工作经验列表
				for(let workExperienceItem of res.data.GZJYList) {
					this.workExperienceClassDataTree.push(
					{
						value: workExperienceItem.ID,
						label: workExperienceItem.JYName
					})
				}
				
				
				// 组合发布天数列表
				if(res.data.FyList.length > 0 && res.data.ZPNum > 0) {
					this.releaseDaysDataTree = res.data.FyList
					this.releaseDays = res.data.FyList[0].ID
				}
				
				console.log(res)
				})
		},

		// 组合全职时职位列表
		fullTimePositionData(){
			for(let [positionItemIndex, positionItem] of this.fullTimePositionClassDataTree.entries()) {
				this.positionClassDataTree.push({
					text: positionItem.ClassName,
					value: positionItem.ID,
					children: []
				})
				for(let positionChildrenItem of positionItem.zwtype_lst) {
					this.positionClassDataTree[positionItemIndex].children.push({
						text: positionChildrenItem.zw_name,
						value: positionChildrenItem.zw_id
					})
				}
			}
		},
		// 组合兼职时职位列表
		partTimePositionData(){
			for(let [positionItemIndex, positionItem] of this.partTimePositionClassDataTree.entries()) {
				this.positionClassDataTree.push({
					text: positionItem.ClassName,
					value: positionItem.ID,
				})
			}
		},

		// 修改选择求职类型
		jobTyypeChange() {
			this.$refs.positionSelect.clear()
			this.positionClass = ''	// 职位类别选择第一层的值ID
			this.positionClassChildren = ''	// 职位类别选择第二层的值ID
			this.positionClassDataTree = [] // 清空职位列表，以便加入兼职列表内容
			this.fullTimeSalary =''  // 清空所选择的薪资待遇
			this.fullTimeMinimumWage = ''  // 清空自定义薪资待遇最低工资
			this.fullTimeMaximumWage = ''  // 清空自定义薪资待遇最高工资
			if(this.jobType == 1) {
				this.fullTimePositionData()
			} else if(this.jobType == 2) {
				this.partTimePositionData()
			}
		},

		// 职位类别选择
		positionOnchange(e) {
			console.log(e)
			if(e.detail.value.length > 0) {
				this.positionClass = e.detail.value[0].value	// 职位类别选择第一层的值ID
				if(this.jobType == 1) {
					this.positionClassChildren = e.detail.value[1].value	// 职位类别选择第二层的值ID
				}
				console.log(this.positionClass, this.positionClassChildren)
			}
		},
		
		// 全职薪资待遇修改
		fullTimeSalaryOnchange() {
			console.log(this.fullTimeSalary)
		},
		
		// 选择工作区域的值
		jobAreaOnchange(e) {
			this.jobCity = e.detail.value[0].value	// 求职区域选择市的值ID
			this.jobArea = e.detail.value[1].value	// 求职区域选择区的值ID
		},
		
		// 选择置顶时间的值
		toppingSelectChange(e) {
			console.log(e)
			console.log(this.topping)
		},
		// 获取坐标
		async getLocation() {
			this.isShowAddressPopup = false
			await uni.getLocation({
				type: 'gcj02',
				geocode: true,
				success: res => {
					this.longitude = res.longitude;
					this.latitude = res.latitude;
					this.getLocationAddress(this.latitude, this.longitude);
					console.log(res);
				}
			});
		},
		// 获取地址
		async getLocationAddress(longitude, latitude) {
			let location = [longitude, latitude];
			let StringLocation = location.toString();
			// console.log(StringLocation)
			await this.$api.getLocationAddress({ get_poi: 1, key: this.$qqMapKey, location: StringLocation }).then(res => {
				console.log(res)
				this.JobAddress = res.result.formatted_addresses.recommend;
			});
		},
		// 地图选址
		selectLocationAddress() {
			this.isShowAddressPopup = false
			uni.chooseLocation({
				success: res => {
					console.log(res);
					this.JobAddress = res.name + '(' + res.address + ')';
					this.longitude = res.longitude;
					this.latitude = res.latitude;
					// this.getRegionFn(res);
				},
				fail: () => {
					// 如果用uni.chooseLocation没有获取到地理位置，则需要获取当前的授权信息，判断是否有地理授权信息
					uni.getSetting({
						success: res => {
							console.log(res);
							var status = res.authSetting;
							if (!status['scope.userLocation']) {
								// 如果授权信息中没有地理位置的授权，则需要弹窗提示用户需要授权地理信息
								uni.showModal({
									title: '是否授权当前位置',
									content: '需要获取您的地理位置，请确认授权，否则地图功能将无法使用',
									success: tip => {
										if (tip.confirm) {
											// 如果用户同意授权地理信息，则打开授权设置页面，判断用户的操作
											uni.openSetting({
												success: data => {
													// 如果用户授权了地理信息在，则提示授权成功
													if (data.authSetting['scope.userLocation'] === true) {
														uni.showToast({
															title: '授权成功',
															icon: 'success',
															duration: 1000
														});
														// 授权成功后，然后再次chooseLocation获取信息
														uni.chooseLocation({
															success: res => {
																console.log("详细地址",res);
																this.JobAddress = res.name + '(' + res.address + ')';
																this.longitude = res.longitude;
																this.latitude = res.latitude;
																// this.getRegionFn(res);
															}
														});
													} else {
														uni.showToast({
															title: '授权失败',
															icon: 'none',
															duration: 1000
														});
													}
												}
											});
										}
									}
								});
							}
						},
						fail: res => {
							uni.showToast({
								title: '调用授权窗口失败',
								icon: 'none',
								duration: 1000
							});
						}
					});
				}
			});
		},
	
	
		// 职位福利选择
		positionWelfareTabsSelect(index, name) {
			let findIndex = this.jobPositionWelfareSelectTabs.findIndex(value => value == this.jobPositionWelfareTabs[index].name);
			if (findIndex == -1) {
				this.jobPositionWelfareSelectTabs.push(this.jobPositionWelfareTabs[index].name);
				this.jobPositionWelfareTabs[index].checked = true;
			} else {
				this.jobPositionWelfareSelectTabs.splice(findIndex, 1);
				this.jobPositionWelfareTabs[index].checked = false;
			}
			if (this.jobPositionWelfareSelectTabs.length > 6) {
				let value = this.jobPositionWelfareSelectTabs.shift()
				for(let welfareItem of this.jobPositionWelfareTabs) {
					if(value == welfareItem.name) {
						welfareItem.checked = false
						break
					}
				}
			}
			console.log(this.jobPositionWelfareSelectTabs);
		},
		// 性别要求选择
		genderSelectChange(val) {
			this.gender = val;
		},
		
		// 年龄要求选择
		ageSelectChange(val) {
			this.age = val;
		},
		
		// 学历要求选择
		educationSelectChange(val) {
			this.education = val;
		},
		
		// 工作经验选择
		workExperienceSelectChange(val) {
			this.workExperience = val;
		},
		
		// 选择兼职时的薪资待遇
		salaryUnitChange(val) {
			this.salaryUnit = val;
		},
		// 选择兼职时的薪资结算方式
		settlementMethodchange(val) {
			this.settlementMethod = val
		},
		
		// 是否显示定位选择菜单
		closeAddressPopup() {
			this.isShowAddressPopup = !this.isShowAddressPopup
		},
		// 删除图片
		deletePic(event) {
			// this[`fileList${event.name}`].splice(event.index, 1);
			this.jobDescriptionImages.splice(event.index, 1);
		},
		
		// 新增图片
		// async afterRead(event) {
		// 	// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
		// 	let lists = [].concat(event.file);
		// 	// let fileListLen = this[`fileList${event.name}`].length;
		// 	let fileListLen = this.jobDescriptionImages.length;
		// 	lists.map(item => {
		// 		// this[`fileList${event.name}`].push({
		// 		this.jobDescriptionImages.push({
		// 			...item,
		// 			status: 'uploading',
		// 			message: '上传中'
		// 		});
		// 	});
		// 	for (let i = 0; i < lists.length; i++) {
		// 		const result = await this.uploadFilePromise(lists[i].thumb);
		// 		// let item = this[`fileList${event.name}`][fileListLen];
		// 		let item = this.jobDescriptionImages[fileListLen]
		// 		// this[`fileList${event.name}`].splice(
		// 		this.jobDescriptionImages.splice(
		// 			fileListLen,
		// 			1,
		// 			Object.assign(item, {
		// 				status: 'success',
		// 				message: '',
		// 				url: result
		// 			})
		// 		);
		// 		fileListLen++;
		// 	}
		// },
		// uploadFilePromise(url) {
		// 	return new Promise((resolve, reject) => {
		// 		let a = uni.uploadFile({
		// 			url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
		// 			filePath: url,
		// 			name: 'file',
		// 			formData: {
		// 				user: 'test'
		// 			},
		// 			success: res => {
		// 				setTimeout(() => {
		// 					resolve(res.data.data);
		// 				}, 1000);
		// 			}
		// 		});
		// 	});
		// },
		
		// 上传图片进行审核
		checkImgReview(tempFilePath) {
			// console.log(tempFilePath[0])
			uni.showLoading({
				title: '上传中'
			});
			return this.$api
				.uploadPictureReview({
					params: {} /* 会加在url上 */,
					// #ifdef APP-PLUS || H5
					// files: [], // 需要上传的文件列表。使用 files 时，filePath 和 name 不生效。App、H5（ 2.6.15+）
					// #endif
		
					// #ifdef MP-ALIPAY
					fileType: 'image/video/audio', // 仅支付宝小程序，且必填。
					// #endif
		
					filePath: tempFilePath, // 要上传文件资源的路径。
					name: 'file_img', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
		
					// #ifdef H5 || APP-PLUS
					timeout: 3000 // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)
					// #endif
				})
				.then(res => {
					uni.hideLoading();
					if (res.errcode == 0) {
						return true;
					} else {
						return false;
					}
				});
		},
		// 上传图片
		uploadPostPositionPicture(tempFilePath) {
			return this.$api.uploadPostPositionPicture({
				params: {} /* 会加在url上 */,
				// #ifdef APP-PLUS || H5
				// files: [], // 需要上传的文件列表。使用 files 时，filePath 和 name 不生效。App、H5（ 2.6.15+）
				// #endif
		
				// #ifdef MP-ALIPAY
				fileType: 'image/video/audio', // 仅支付宝小程序，且必填。
				// #endif
		
				filePath: tempFilePath, // 要上传文件资源的路径。
				name: 'imgurl', // 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容
				// #ifdef H5 || APP-PLUS
				timeout: 3000 // H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)
				// #endif
		
				// header: {}, /* 会与全局header合并，如有同名属性，局部覆盖全局 */
				// custom: {}, // 自定义参数
				// formData: {xxid:infoId}, // HTTP 请求中其他额外的 form data
				// // 返回当前请求的task, options。请勿在此处修改options。非必填
				// getTask: (task, options) => {
				//   // setTimeout(() => {
				//   //   task.abort()
				//   // }, 500)
				// }
			})
				.then(res => {
					uni.hideLoading();
					// console.log(res);
					return res.data
					// resolve(res);
				})
				// .catch(err => {
				// 	uni.hideLoading();
				// 	console.log(err);
				// 	reject(err);
				// });
		},
		
		// 职位描述图片管理
		jobDescriptionImageListSelect(e) {
			// 审核选择图片
			this.checkImgReview(e.tempFilePaths[0]).then(res => {
				if (!res) {
					this.showMessage('error', '图片违规，自动删除', 'center');
					this.$refs.jobDescriptionImageList.clearFiles(-1);
				} else {
					this.uploadPostPositionPicture(e.tempFilePaths[0]).then(res => {
						this.jobDescriptionImages.push(...[{
									name: res.Pic,
									extname: e.tempFiles[0].extname,
									url: this.$getImgUrl(res.Imgpath),
						}])
					})
					console.log('jobDescriptionImageList:', this.jobDescriptionImages)
				}
			});
		},
		// 删除职位描述图片
		jobDescriptionImageListDelete(e) {
			let index = this.jobDescriptionImages.findIndex(item => item.url == e.tempFilePath);
			this.jobDescriptionImages.splice(index, 1);
			console.log(this.jobDescriptionImages);
		},
		
		// 校验文字
		checkTextContent(value) {
			// console.log(value)
			if (value.length > 0) {
				this.$api.checkTextContent({ filewz: value }).then(res => {
					if (res.errcode != 0) {
						this.showMessage('error', '文字内容违规，请修改文字内容', 'center');
					}
				});
			}
		},
		
		// 选择发布时间
		jobReleaseDaysSelect(val) {
			this.releaseDays = val
		},
		
		// 提交表单
		infoSubmit(){
			this.isSubmit = true
			// 组合职位类别参数
			this.infoParams['ZPType'] = this.jobType
			// 判断并组合是否输入职位名称
			if(this.jobTitle =='') {
				this.showMessage('warning', '请输入职位名称', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['ZWName'] = this.jobTitle
			}
			
			// 判断职位类型是否是全职
			if(this.jobType == 1) {
				// 判断并组合是否选择职位类别
				if(this.positionClassChildren == '') {
					this.showMessage('warning', '请选择职位类别', 'center');
					this.isSubmit = false;
					return
				} else {
					this.infoParams['ZWID1'] = this.positionClass
					this.infoParams['ZWID2'] = this.positionClassChildren
				}
				
				// 判断并组合薪资待遇
				if(this.fullTimeSalary.length == 0) {
					this.showMessage('warning', '请选薪资待遇', 'center');
					this.isSubmit = false;
					return
				} else {
					this.infoParams['XZID'] = this.fullTimeSalary
				}
				
				// 判断选择薪资待遇是自定义时是否添加最低和最高工资
				if(this.fullTimeSalary == '0') {
					// 判读输入正确的最低工资
					if(this.fullTimeMinimumWage.length == 0) {
						this.showMessage('warning', '请输入待遇最低工资', 'center');
						this.isSubmit = false;
						return
					} else if(Number.isNaN(this.fullTimeMinimumWage)) {
						this.showMessage('warning', '请正确输入待遇最低工资', 'center');
						this.isSubmit = false;
						return
					} else {
						this.infoParams['XZMin'] = this.fullTimeMinimumWage
					}
					
					// 判读输入正确的最高工资
					if(this.fullTimeMaximumWage.length == 0) {
						this.showMessage('warning', '请输入待遇最高工资', 'center');
						this.isSubmit = false;
						return
					} else if(Number.isNaN(this.fullTimeMaximumWage)) {
						this.showMessage('warning', '请正确输入待遇最高工资', 'center');
						this.isSubmit = false;
						return
					} else {
						this.infoParams['XZMax'] = this.fullTimeMaximumWage
					}
				}
			}
			// 判断职位类型是否是兼职
			if(this.jobType == 2) {
				// 判断并组合是否选择职位类别
				if(this.positionClass == '') {
					this.showMessage('warning', '请选择职位类别', 'center');
					this.isSubmit = false;
					return
				} else {
					this.infoParams['ZWID1'] = this.positionClass
				}
				
				// 判断并组合薪资待遇
				if(this.partTimeSalary == '') {
					this.showMessage('warning', '请输入薪资待遇', 'center');
					this.isSubmit = false;
					return
				} else {
					this.infoParams['XZPrice'] = this.partTimeSalary
					
				}
				
				// 判断组合薪算单位
				for(let salaryUnitItem of this.salaryUnitClassDataTree) {
					if(salaryUnitItem.value == this.salaryUnit) {
						this.infoParams['XZDanWei'] = salaryUnitItem.label
						break
					}
				}
				
				// 组合薪资结算方式
				this.infoParams['JSType'] = this.settlementMethod
				
				
			}
			
			// 组合招聘人数
			if(this.jobRecruitNumber =='') {
				this.infoParams['ZPNum'] = ''
			} else if(Number.isNaN(this.this.jobRecruitNumber)) {
				this.showMessage('warning', '请正确输入招聘人数', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['ZPNum'] = this.jobRecruitNumber
			}
			
			// 组合职位福利
			if(this.jobPositionWelfareSelectTabs.length > 0) {
				this.infoParams['ZWFuLi'] = this.jobPositionWelfareSelectTabs.join(',')
			}
			
			// 组合公司名称
			if(this.companyName== '') {
				this.showMessage('warning', '请输入工资名称', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['Company'] = this.companyName
			}
			
			// 组合工作区域
			if(this.jobArea == '') {
				this.showMessage('warning', '请选择工作区域', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['ProID'] = this.jobCity
				this.infoParams['CityID'] = this.jobArea
			}

			// 组合工作地址
			if(this.JobAddress == '') {
				this.showMessage('warning', '请输入工作地址', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['Address'] = this.JobAddress
			}
			// 组合工作地址坐标
			this.infoParams['ZuoBiao'] = this.latitude + ',' + this.longitude
			// 组合联系人
			if(this.contacts == '') {
				this.showMessage('warning', '请输入联系人', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['LXPerson'] = this.contacts
			}
			// 组合联系电话
			if(this.contactsNumber == '') {
				this.showMessage('warning', '请输入联系电话', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['LXPhone'] = this.contactsNumber
			}
			//  组合置顶选项
			if(this.topping.length == 0) {
				this.showMessage('warning', '请选择置顶时间', 'center');
				this.isSubmit = false;
				return
			} else {
				this.infoParams['TFeeID'] = this.topping
			}
			// 组合性别要求
			if(this.gender.length == 0) {
				this.showMessage('warning', '请选择性别要求', 'center');
				this.isSubmit = false;
				return
			} else {
				for(let sexItem of this.genderClassDataTree) {
					if(sexItem.value== this.gender) {
						this.infoParams['Sex'] = sexItem.label
						break
					}
				}
			}
			
			// 组合年龄要求
			this.infoParams['AgeID'] = this.age
			// 组合学历要求
			this.infoParams['XuLiID'] = this.education
			// 组合工作经验
			this.infoParams['GZJYID'] = this.workExperience
			// 组合职位描述
			this.infoParams['ZWMS'] = this.jobDescription
			// 组合职位介绍图片
			if(this.jobDescriptionImages.length > 0) {
				// 组合企业图片参数
				let tempImageItem = ''
				for(let imageItem of  this.jobDescriptionImages) {
					tempImageItem = tempImageItem +  imageItem.name + ','
				}				
				this.infoParams['ZWPic'] = tempImageItem.slice(0, tempImageItem.length - 1)
			} else {
				this.infoParams['ZWPic'] = ''
			}
			
			// 判断发布类型
			if(this.positionReleasesNumber >0) {
				// 购买套餐的会员并还有发布条数
				if(this.topping > 0) {
					this.infoParams['FBType'] =1
				} else {
					this.infoParams['FBType'] =2
				}
				this.infoParams['FeeID'] =0
			} else {
				// 非购买套餐使用免费发布条数会员
				this.infoParams['FeeID'] = this.releaseDays // 免费发布发布天数ID
				if(this.topping > 0 && this.releaseDays > 0) {
					this.infoParams['FBType'] =3
				} else if(this.topping == 0 && this.releaseDays > 0) {
					this.infoParams['FBType'] =4
				}
			}
			
			console.log(this.infoParams)
			
			if(this.isSubmit) {
				this.$api.postJobPostPosition(this.infoParams).then(res => {
					uni.$u.route('/pages/jobMe/jobMe')
				})
			}

		},
		
		// 跳转购买套餐
		goToBuyVip() {
			uni.navigateTo({
			    url: '../jobMyBuyVip/jobMyBuyVip',
			});
		},
		// 跳转认证页面
		goToEnterPriseAuth() {
			uni.navigateTo({
			    url: '/pages/jobMyEnterPriseAuth/jobMyEnterPriseAuth',
			});
		},
		showMessage(type, title, direction) {
			//显示message
			this.$refs.message.show({
				type: type, //默认default
				msg: title, //显示内容
				icon: true, //显示icon
				mask: false, //遮罩
				time: 3000, //显示时间
				direction: direction //方向
			});
			let id = this.$refs.message.id; //获取弹窗id,需要在弹出后获取
			setTimeout(() => {
				this.$refs.message.close(id); //关闭某个弹窗
			}, 3000);
			// if(this.messageData.time===false){
			// 	if(this.messageData.mask){
			// 		this.$refs.message.show({
			// 			type:'warning',
			// 			msg:'注意!! 当前遮罩已开启,不可点击,为了方便测试这里设置了10秒后关闭当前消息,你也可以关闭指定某个消息,详情查看说明文档及demo.',
			// 			time:10000
			// 		})
			// 		setTimeout(()=>{
			// 			this.$refs.message.close(id); //关闭某个弹窗
			// 		},10000)
			// 	}
			// }
		}
	},
	computed: {
		isIosPhone: function() {
			return getApp().globalData.systemType == 'ios'
		}
	},
	components: {
		QuickMessage,
	}

};
</script>

<style lang="scss" scoped>
@import url('jopPostPosition.css');
</style>
